package com.yao.sample.controller;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import com.yao.sample.po.Word;

@Stateless
@Path("/")
@Produces({ "text/xml", "application/json" })
public class WordController {
	@PersistenceContext(type = PersistenceContextType.TRANSACTION)
	private EntityManager em;

	@GET
	@Path("/detail/{spelling}")
	public Word detail(@PathParam("spelling") String spelling) {
		return em.find(Word.class, spelling);
	}

	@POST
	@Path("/create")
	public Word create(Word word) {
//		SimpleMean simpleMean = new SimpleMean();
//		simpleMean.setMeanItems(Arrays.asList(new MeanItem(new PartsOfSpeech[] {
//				PartsOfSpeech.adj, PartsOfSpeech.vi }, "意思，意义；含义；意图")));
//		word.setSimpleMean(simpleMean);
		em.persist(word);
		return word;
	}
}
